package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Qq;
import com.ruoyi.system.service.IQqService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * qq账号 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-05-28
 */
@Controller
@RequestMapping("/system/qq")
public class QqController extends BaseController
{
    private String prefix = "system/qq";
	
	@Autowired
	private IQqService qqService;
	
	@RequiresPermissions("system:qq:view")
	@GetMapping()
	public String qq()
	{
	    return prefix + "/qq";
	}
	
	/**
	 * 查询qq账号列表
	 */
	@RequiresPermissions("system:qq:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Qq qq)
	{
		startPage();
        List<Qq> list = qqService.selectQqList(qq);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出qq账号列表
	 */
	@RequiresPermissions("system:qq:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Qq qq)
    {
    	List<Qq> list = qqService.selectQqList(qq);
        ExcelUtil<Qq> util = new ExcelUtil<Qq>(Qq.class);
        return util.exportExcel(list, "qq");
    }
	
	/**
	 * 新增qq账号
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存qq账号
	 */
	@RequiresPermissions("system:qq:add")
	@Log(title = "qq账号", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Qq qq)
	{		
		return toAjax(qqService.insertQq(qq));
	}

	/**
	 * 修改qq账号
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Qq qq = qqService.selectQqById(id);
		mmap.put("qq", qq);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存qq账号
	 */
	@RequiresPermissions("system:qq:edit")
	@Log(title = "qq账号", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Qq qq)
	{		
		return toAjax(qqService.updateQq(qq));
	}
	
	/**
	 * 删除qq账号
	 */
	@RequiresPermissions("system:qq:remove")
	@Log(title = "qq账号", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(qqService.deleteQqByIds(ids));
	}
	
}
